<template>
  <div class="login-container">
    <h2 class="login-title">健身私教App管理系统</h2>
    <a-form ref="form" :model="form" class="login-form">
      <a-form-item>
        <a-input v-model="form.username">
          <a-icon slot="prefix" type="user"/>
        </a-input>
      </a-form-item>
      <a-form-item>
        <a-input-password v-model.trim="form.password">
          <a-icon slot="prefix" type="unlock"/>
        </a-input-password>
      </a-form-item>
      <a-form-item>
        <a-button class="submit" type="primary" @click="onSubmit">登录</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
import qs from 'qs'
import { login } from '../http/api'
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    onSubmit() {
      login(qs.stringify(this.form)).then(res => {
        if (res.code === 0) {
          // 登陆成功，存储 token
          localStorage.setItem('token', res.token)
          // 登陆成功，存储 当前登录用户信息
          localStorage.setItem('user', JSON.stringify(res.user))
          // 跳转后台主页
          this.$router.push('/system_navigation')
          this.$message.success(res.msg)
        } else {
          // 登录失败
          localStorage.removeItem('token')
          localStorage.removeItem('user')
          this.$message.error(res.msg)
        }
      })
    }
  }
}
</script>

<style scoped>
.login-form {
  width: 565px;
  height: 372px;
  margin: 0 auto;
  /*background: url("../assets/img_1.png");*/
  padding: 40px 110px;
}

/* 背景 */
.login-container {
  position: absolute;
  width: 100%;
  height: 100%;
  background: url("../assets/122CCCBD8AEA52402EFB174116588173.jpg") no-repeat;
  background-size: 100% 100%;
}

/* Log */
.login-title {
  color: #fff;
  text-align: center;
  margin: 100px 0 60px 0;
  font-size: 36px;
  font-family: Microsoft Yahei;
}

/* 登陆按钮 */
.submit {
  width: 100%;
  height: 45px;
  font-size: 16px;
}

/* 用户登陆标题 */
.title {
  margin-bottom: 50px;
  color: #fff;
  font-weight: 700;
  font-size: 24px;
  font-family: Microsoft Yahei;
}

/* 输入框 */
.inputBox {
  height: 45px;
}

/* 输入框内左边距50px */
.ant-input-affix-wrapper .ant-input:not(:first-child) {
  padding-left: 50px;
}
</style>
